﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>登录页面</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.6.8/css/layui.min.css">
    <style>
        body {
            background: linear-gradient(to bottom right, #007bff, #00c6ff);
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }

        .layui-card {
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            overflow: hidden;
            animation: fadeInUp 0.5s ease;
        }

        

        .layui-card-header {
            background-color: #007bff;
            color: white;
            text-align: center;
            padding: 20px;
            font-size: 24px;
            font-weight: bold;
        }

        .layui-form {
            padding: 20px;
        }

        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-form-label {
            font-weight: bold;
            color: #333;
        }

        .layui-input {
            border-radius: 5px;
            border: 1px solid #ccc;
            padding: 10px;
            width: 100%;
            transition: border-color 0.3s ease;
        }

            .layui-input:focus {
                border-color: #007bff;
                outline: none;
            }

        .layui-btn {
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 5px 20px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

            .layui-btn:hover {
                background-color: #0056b3;
            }

        .layui-btn-primary {
            background-color: white;
            color: #333;
            border: 1px solid #ccc;
        }

            .layui-btn-primary:hover {
                background-color: #f4f4f4;
            }

    </style>
</head>

<body>
    <div class="layui-container">
        <div class="layui-row layui-col-space50">
            <div class="layui-col-md4 layui-col-md-offset4">
                <div class="layui-card">
                    <div class="layui-card-header">用户登录</div>
                    <div class="layui-card-body">
                        <form class="layui-form" id="loginForm">
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="pass" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="login">登录</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.staticfile.org/jquery/3.6.4/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/layui/2.6.8/layui.min.js"></script>
    <script>
        function setCookie(name, value, days) {
            let expires = "";
            if (days) {
                const date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                expires = "; expires=" + date.toUTCString();
            }
            document.cookie = name + "=" + (value || "") + expires + "; path=/";
        }

        layui.use(['form', 'layer'], function () {
            const form = layui.form;
            const layer = layui.layer;

            form.on('submit(login)', function (data) {
                const name = encodeURIComponent(data.field.name);
                const pass = encodeURIComponent(data.field.pass);
                const userId = encodeURIComponent(data.field.userId);
                $.ajax({
                    //url: `https://localhost:7171/api/Login/Login?Name=${name}&Pass=${pass}`,
                    url: `@ViewBag.BaseUrl/T5/Login/Login?Name=${name}&Pass=${pass}`,
                    type: 'GET',
                    success: function (res) {
                        console.log(res);
                        if (res.code === 100) {
                            // 存储用户名和密码到 Cookie
                            setCookie('id', res.data.userId, 7);
                            setCookie('name', res.data.name, 7);
                            // localStorage.setItem('name',res.data.name);
                            // console.log("name",res.data.name);
                            // localStorage.setItem('pass',res.pass,7);
                            setCookie('pass', res.data.pass, 7);
                            layer.msg('登录成功', { icon: 1 }, function () {
                                window.location.href = '@Url.Action("MenuNnavigation", "Menu")';
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.msg('请求出错，请稍后重试', { icon: 2 });
                    }
                });
                return false;
            });
        });
    </script>
</body>

</html>    